package com.zhou.base.components.bs.common.properties.convert;

import org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

@Component
@ConfigurationPropertiesBinding
public class YearMonthConverter implements Converter<Integer, YearMonth> {

    private static DateTimeFormatter YEAR_MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyyMM");

    @Override
    public YearMonth convert(Integer from) {
        return YearMonth.parse(from + "", YEAR_MONTH_FORMATTER);
    }
}
